package com.meisiabc.app.repository.db.manager;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meisiabc.app.repository.db.constant.OrderStatus;
import com.meisiabc.app.repository.db.entity.PurchaseCourse;
import com.meisiabc.app.repository.db.mapper.PurchaseCourseMapper;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PurchaseCourseManager extends ServiceImpl<PurchaseCourseMapper, PurchaseCourse> {
    public List<PurchaseCourse> selectByStudentId(String studentId) {
            return list(new QueryWrapper<PurchaseCourse>().eq("student_id", studentId));
    }

    public List<PurchaseCourse> selectByStudentId(String studentId, String ispay) {
        return list(new QueryWrapper<PurchaseCourse>().eq("student_id", studentId).eq("is_pay", ispay).orderByDesc("id"));
    }

    public PurchaseCourse selectByIdAndStudentId(String lessonId, String studentId) {
        return getOne(new QueryWrapper<PurchaseCourse>().eq("uniqueid", lessonId).eq("student_id", studentId));
    }

    public void updateByUniqueidSelective(String orderId, OrderStatus status) {
        update(PurchaseCourse.builder().isPay(status.getDesc()).build(), new QueryWrapper<PurchaseCourse>().eq("uniqueid", orderId));
    }


}
